package com.ryan.security.browser;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * Created by kaimin on 1/1/2019.
 * time : 15:51
 */
@Component
@Slf4j
public class MyUserDetailService implements UserDetailsService {

//    @Autowired
//    private dao xx; 可以注入自己的crm框架

    @Autowired//自定义的密码策略
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //根据用户明查找用户信息
        log.info("登录用户名是："+username);
        //实际应用是要从数据库中获取的

        //实现一些逻辑
//        根据查找的用户是否被冻结

//        return new User(username,"123456", AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
        return new User(username,passwordEncoder.encode("123456"),
                true,true,true,true,
                AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
